package com.guaju.yueshangLife.viewmodel.login;

import android.content.Intent;
import android.databinding.BaseObservable;
import android.text.TextUtils;
import android.view.View;

import com.guaju.yueshangLife.activity.CodeLoginActivity;
import com.guaju.yueshangLife.activity.FindPasswordActivity;
import com.guaju.yueshangLife.activity.RegistActivity;
import com.guaju.yueshangLife.bean.CodeLoginEvent;
import com.guaju.yueshangLife.net.ApiClient;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.utils.NotifyUtil;
import com.guaju.yueshangLife.utils.ToastUtil;

/**
 * Created by guaju on 2018/10/12.
 */

public class LoginVM extends BaseObservable{


    public String phoneNum;
    public String password;
    private Intent intent;


    public void login(String phoneNum, String password){
        if (!NotifyUtil.isPhoneNum(phoneNum)){
            ToastUtil.show("手机号格式不正确,请修改");
        }else if (TextUtils.isEmpty(password)){
            ToastUtil.show("密码错误,请检查");
        }else{
            //服务器校验
            ApiEntity.login(phoneNum,password);
        }
    }

    public void login(View v){
       login(phoneNum,password);
       v.setClickable(false);
    }
    public void toRegist (View v){
        intent = new Intent(v.getContext(), RegistActivity.class);
        v.getContext().startActivity(intent);
    }
    public void toCodeLogin (View v){
        intent = new Intent(v.getContext(), CodeLoginActivity.class);
        v.getContext().startActivity(intent);
    }
    public void toFindPassword(View v){
        intent = new Intent(v.getContext(), FindPasswordActivity.class);
        v.getContext().startActivity(intent);
    }
}
